﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using DocumentsTagger.DM;

namespace DocumentsTagger.UI.ViewModel
{
    public class TagsViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private ObservableCollection<TagsDetailsViewModel> m_Tags;
        private TagsDetailsViewModel m_SelectedTag;

        public TagsDetailsViewModel SelectedTag
        {
            get { return m_SelectedTag; }
            set
            {
                m_SelectedTag = value;
                NotifyPropertyChanged("SelectedTag");
            }
        }
  
        public ObservableCollection<TagsDetailsViewModel> Tags
        {
            get { return m_Tags; }
            set
            {
                m_Tags = value;
                NotifyPropertyChanged("Tags");
            }
        }


        public TagsViewModel()
        {
            List<Tag> currentTags = TagsFactory.Tags;
            List<TagsDetailsViewModel> vmList = new List<TagsDetailsViewModel>();

            foreach (Tag tag in currentTags)
            {
                vmList.Add(new TagsDetailsViewModel(tag));
            }

            this.Tags = new ObservableCollection<TagsDetailsViewModel>(vmList);
        }

        /// <summary>
        /// initiated the notification process
        /// </summary>
        /// <param name="info"></param>
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

    }
}
